//app.js
const updateManager = wx.getUpdateManager()

App({


  "pages": ["pages/index/index"],
  "permission": {
    "scope.userLocation": {
      "desc": "你的位置信息将用于小程序位置接口的效果展示"
    }
  },


  onLaunch: function () {
    this.getopenidfunc();
    wx.setStorageSync('mallName', "首页");
    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
    // 登录
    // 获取用户信息
    wx.getSetting({
      success: res => {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称，不会弹框
          wx.getUserInfo({
            success: res => {
              // 可以将 res 发送给后台解码出 unionId
              this.globalData.userInfo = res.userInfo
              console.log(res.userInfo)
              // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
              // 所以此处加入 callback 以防止这种情况
              if (this.userInfoReadyCallback) {
                this.userInfoReadyCallback(res)
              }
            }
          })
        }
      }
    })

  },




  // add h 20190603 start
  getopenidfunc: function () {


    var that = this

    wx.login({
      success: function (res) {

        //发送请求
        wx.request({
          url: 'http://127.0.0.1:8080/mfyy/goc/getopenid', //接口地址
          data: { code: res.code },
          header: {
            'content-type': 'application/json' //默认值
          },
          success: function (res) {

            that.globalData.openid = res.data.openid;
              console.log("openid:"+res.data.openid)

          },

          fail: function (error) {
            console.info("获取用户openId失败");
            console.info(error);
          }
        })
      }
    })


  },


  globalData: {
    statusBarHeight: wx.getSystemInfoSync()['statusBarHeight'],
    userInfo: null,
    openid: null,
    headurl: 'http://127.0.0.1:8080/mfyy',
    role: 0,
    historylist: [],
    customer:'',
    address:''
  }
})